<!DOCTYPE html>
<html>
<head>
    <meta charset='utf-8'>
    <meta http-equiv='X-UA-Compatible' content='IE=edge'>
    <title>Page Title</title>
    <meta name='viewport' content='width=device-width, initial-scale=1'>
    <link rel='stylesheet' type='text/css' media='screen' href='main.css'>
    <script src='main.js'></script>
</head>
<body>
    
</body>
<script>
// 1. 格式化日期对象为 yyyy-MM-dd HH:mm:ss
function formatDate(date) {
    const padZero = num => num.toString().padStart(2, '0');
    
    return `${date.getFullYear()}-${
        padZero(date.getMonth() + 1)}-${
        padZero(date.getDate())} ${
        padZero(date.getHours())}:${
        padZero(date.getMinutes())}:${
        padZero(date.getSeconds())}`;
}

// 测试示例
console.log("当前日期格式化结果：", formatDate(new Date()));    
</script>
<script>
    // 2. 计算时间差，返回相差的天/时/分/秒
function getTimeDifference(startDate, endDate) {
    const diffMs = endDate - startDate;
    const days = Math.floor(diffMs / (1000 * 60 * 60 * 24));
    const hours = Math.floor((diffMs % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
    const minutes = Math.floor((diffMs % (1000 * 60 * 60)) / (1000 * 60));
    const seconds = Math.floor((diffMs % (1000 * 60)) / 1000);
    
    return { days, hours, minutes, seconds };
}

// 测试示例
const start = new Date('2023-01-01');
const end = new Date('2023-01-10');
const diff = getTimeDifference(start, end);
console.log(`相差 ${diff.days} 天 ${diff.hours} 时 ${diff.minutes} 分 ${diff.seconds} 秒`);    
</script>
</html>